1 Imports System.Data.SqlClient
2 Imports System.IO
3
4 Public Class frmStaff
5 Dim s1 As String
6 Dim Photoname As String = ""
7 Dim IsImageChanged As Boolean = False
8 Dim gender As String
9 Private Sub auto()
10 Try
11 Dim Num As Integer = 0
12 con = New SqlConnection(cs)
13 con.Open()
14 Dim sql As String = ("SELECT MAX(St_ID) FROM Staff")
15 cmd = New SqlCommand(sql)
16 cmd.Connection = con
17 If (IsDBNull(cmd.ExecuteScalar)) Then
18 Num = 1
19 txtID.Text = Num.ToString
20 txtStaffID.Text = "S-" + Num.ToString
21 Else
22 Num = cmd.ExecuteScalar + 1
23 txtID.Text = Num.ToString
24 txtStaffID.Text = "S-" + Num.ToString
25 End If
26 cmd.Dispose()
27 con.Close()
28 con.Dispose()
29 Catch ex As Exception
30 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
31 End Try
32 End Sub
33 Sub fillSchool()
34 Try
35 con = New SqlConnection(cs)
36 con.Open()
37 adp = New SqlDataAdapter()
38 adp.SelectCommand = New SqlCommand("SELECT distinct (SchoolName) FROM SchoolInfo", con)
39 ds = New DataSet("ds")
40 adp.Fill(ds)
41 dtable = ds.Tables(0)
42 cmbSchoolName.Items.Clear()
43 For Each drow As DataRow In dtable.Rows
44 cmbSchoolName.Items.Add(drow(0).ToString())
45 Next
46 Catch ex As Exception
47 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
48 End Try
49 End Sub
50 Sub fillClassType()
51 Try
52 con = New SqlConnection(cs)
53 con.Open()
54 adp = New SqlDataAdapter()
55 adp.SelectCommand = New SqlCommand("SELECT distinct (Type) FROM ClassType", con)
56 ds = New DataSet("ds")
57 adp.Fill(ds)
58 dtable = ds.Tables(0)
59 cmbClassType.Items.Clear()
60 For Each drow As DataRow In dtable.Rows
61 cmbClassType.Items.Add(drow(0).ToString())
62 Next
63 Catch ex As Exception
64 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
65 End Try
66 End Sub
67 Sub Reset()
68 txtStaffID.Text = ""
69 cmbDepartment.SelectedIndex = -1
70 cmbDesignation.SelectedIndex = -1
71 cmbStatus.SelectedIndex = -1
72 ListView1.Items.Clear()
73 txtEmail.Text = ""
74 txtFatherName.Text = ""
75 txtMobileNo.Text = ""
76 txtPermanentAddress.Text = ""
77 txtPhoneNo.Text = ""
78 txtStaffName.Text = ""
79 txtTempAddress.Text = ""
80 txtPermanentAddress.Text = ""
81 dtpDateOfJoining.Text = Today
82 dtpDOB.Text = Today
83 cmbDepartment.SelectedIndex = -1
84 cmbClassType.SelectedIndex = -1
85 cmbSchoolName.SelectedIndex = -1
86 txtAccountName.Text = ""
87 txtQualifications.Text = ""
88 txtAccountNo.Text = ""
89 txtBank.Text = ""
90 txtBranch.Text = ""
91 txtIFSCcode.Text = ""
92 txtBasicSalary.Text = ""
93 Picture.Image = My.Resources.photo
94 rbMale.Checked = False
95 rbFemale.Checked = False
96 btnSave.Enabled = True
97 btnDelete.Enabled = False
98 btnUpdate.Enabled = False
99 txtStaffName.Focus()
100 auto()
101 End Sub
102
103
104 Private Sub Browse_Click_1(sender As System.Object, e As System.EventArgs) Handles Browse.Click
105 Try
106 With OpenFileDialog1
107 .Filter = ("Images |*.png; *.bmp; *.jpg;*.jpeg; *.gif;")
108 .FilterIndex = 4
109 End With
110 'Clear the file name
111 OpenFileDialog1.FileName = ""
112 If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
113 Picture.Image = Image.FromFile(OpenFileDialog1.FileName)
114 End If
115 Catch ex As Exception
116 MsgBox(ex.ToString())
117 End Try
118 End Sub
119
120 Private Sub BRemove_Click(sender As System.Object, e As System.EventArgs) Handles BRemove.Click
121 Picture.Image = My.Resources.photo
122 End Sub
123
124 Private Sub BStartCapture_Click(sender As System.Object, e As System.EventArgs) Handles BStartCapture.Click
125 Dim k As New frmCamera
126 k.ShowDialog()
127 If TempFileNames2.Length > 0 Then
128
129 Picture.Image = Image.FromFile(TempFileNames2)
130 Photoname = TempFileNames2
131 IsImageChanged = True
132 End If
133 End Sub
134
135 Private Sub btnNew_Click(sender As System.Object, e As System.EventArgs) Handles btnNew.Click
136 Reset()
137 End Sub
138
139 Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click
140 Try
141 If Len(Trim(txtStaffName.Text)) = 0 Then
142 MessageBox.Show("Please enter staff name", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
143 txtStaffName.Focus()
144 Exit Sub
145 End If
146 If rbMale.Checked = False And rbFemale.Checked = False Then
147 MessageBox.Show("Please select gender", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
148 Exit Sub
149 Exit Sub
150 End If
151 If Len(Trim(txtFatherName.Text)) = 0 Then
152 MessageBox.Show("Please enter father's name", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
153 txtFatherName.Focus()
154 Exit Sub
155 End If
156 If Len(Trim(cmbDesignation.Text)) = 0 Then
157 MessageBox.Show("Please select designation", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
158 cmbDesignation.Focus()
159 Exit Sub
160 End If
161 If Len(Trim(txtTempAddress.Text)) = 0 Then
162 MessageBox.Show("Please enter temporary address", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
163 txtTempAddress.Focus()
164 Exit Sub
165 End If
166 If Len(Trim(txtPermanentAddress.Text)) = 0 Then
167 MessageBox.Show("Please enter permanent address", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
168 txtPermanentAddress.Focus()
169 Exit Sub
170 End If
171 If Len(Trim(txtMobileNo.Text)) = 0 Then
172 MessageBox.Show("Please enter mobile no.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
173 txtMobileNo.Focus()
174 Exit Sub
175 End If
176 If Len(Trim(txtBasicSalary.Text)) = 0 Then
177 MessageBox.Show("Please enter basic salary", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
178 txtBasicSalary.Focus()
179 Exit Sub
180 End If
181 If ListView1.Items.Count = 0 Then
182 MessageBox.Show("Please add department to listview", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
183 cmbDepartment.Focus()
184 Exit Sub
185 End If
186 If Len(Trim(cmbSchoolName.Text)) = 0 Then
187 MessageBox.Show("Please select school name", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
188 cmbSchoolName.Focus()
189 Exit Sub
190 End If
191 If Len(Trim(cmbClassType.Text)) = 0 Then
192 MessageBox.Show("Please select class type", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
193 cmbClassType.Focus()
194 Exit Sub
195 End If
196 If Len(Trim(txtAccountName.Text)) = 0 Then
197 MessageBox.Show("Please enter account name", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
198 txtAccountName.Focus()
199 Exit Sub
200 End If
201 If Len(Trim(txtAccountNo.Text)) = 0 Then
202 MessageBox.Show("Please enter account no.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
203 txtAccountNo.Focus()
204 Exit Sub
205 End If
206 If Len(Trim(txtBank.Text)) = 0 Then
207 MessageBox.Show("Please enter bank", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
208 txtBank.Focus()
209 Exit Sub
210 End If
211 If Len(Trim(txtBranch.Text)) = 0 Then
212 MessageBox.Show("Please enter branch", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
213 txtBranch.Focus()
214 Exit Sub
215 End If
216 If Len(Trim(cmbStatus.Text)) = 0 Then
217 MessageBox.Show("Please select status", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
218 cmbStatus.Focus()
219 Exit Sub
220 End If
221 If rbMale.Checked = True Then
222 gender = rbMale.Text
223 End If
224 If rbFemale.Checked = True Then
225 gender = rbFemale.Text
226 End If
227 con = New SqlConnection(cs)
228 con.Open()
229 Dim cb As String = "insert into Staff( St_ID, StaffID, StaffName, DateOfJoining, Gender, FatherName, TemporaryAddress, PermanentAddress, Designation, Qualifications, DOB, PhoneNo, MobileNo, Email, Photo,Status,SchoolID,ClassType,Salary,AccountName,AccountNumber,Bank,Branch,IFSCcode) VALUES (@d1,@d2,@d3,@d4,@d5,@d6,@d7,@d8,@d9,@d10,@d11,@d12,@d13,@d14,@d15,'" & cmbStatus.Text & "',@d16,@d17,@d18,@d19,@d20,@d21,@d22,@d23)"
230 cmd = New SqlCommand(cb)
231 cmd.Connection = con
232 cmd.Parameters.AddWithValue("@d1", txtID.Text)
233 cmd.Parameters.AddWithValue("@d2", txtStaffID.Text)
234 cmd.Parameters.AddWithValue("@d3", txtStaffName.Text)
235 cmd.Parameters.AddWithValue("@d4", dtpDateOfJoining.Text)
236 cmd.Parameters.AddWithValue("@d5", gender)
237 cmd.Parameters.AddWithValue("@d6", txtFatherName.Text)
238 cmd.Parameters.AddWithValue("@d7", txtTempAddress.Text)
239 cmd.Parameters.AddWithValue("@d8", txtPermanentAddress.Text)
240 cmd.Parameters.AddWithValue("@d9", cmbDesignation.Text)
241 cmd.Parameters.AddWithValue("@d10", txtQualifications.Text)
242 cmd.Parameters.AddWithValue("@d11", dtpDOB.Text)
243 cmd.Parameters.AddWithValue("@d12", txtPhoneNo.Text)
244 cmd.Parameters.AddWithValue("@d13", txtMobileNo.Text)
245 cmd.Parameters.AddWithValue("@d14", txtEmail.Text)
246 cmd.Parameters.AddWithValue("@d16", txtSchoolID.Text)
247 cmd.Parameters.AddWithValue("@d17", cmbClassType.Text)
248 cmd.Parameters.AddWithValue("@d18", txtBasicSalary.Text)
249 cmd.Parameters.AddWithValue("@d19", txtAccountName.Text)
250 cmd.Parameters.AddWithValue("@d20", txtAccountNo.Text)
251 cmd.Parameters.AddWithValue("@d21", txtBank.Text)
252 cmd.Parameters.AddWithValue("@d22", txtBranch.Text)
253 cmd.Parameters.AddWithValue("@d23", txtIFSCcode.Text)
254 Dim ms As New MemoryStream()
255 Dim bmpImage As New Bitmap(Picture.Image)
256 bmpImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
257 Dim data As Byte() = ms.GetBuffer()
258 Dim p As New SqlParameter("@d15", SqlDbType.Image)
259 p.Value = data
260 cmd.Parameters.Add(p)
261 cmd.ExecuteNonQuery()
262 For i = 0 To ListView1.Items.Count - 1
263 con = New SqlConnection(cs)
264 Dim cd As String = "insert Into Staff_Department(StaffID,DepartmentID) VALUES (@d1,@d2)"
265 cmd = New SqlCommand(cd)
266 cmd.Connection = con
267 cmd.Parameters.AddWithValue("@d1", txtID.Text)
268 cmd.Parameters.AddWithValue("@d2", CInt(ListView1.Items(i).SubItems(1).Text))
269 con.Open()
270 cmd.ExecuteNonQuery()
271 con.Close()
272 Next
273 con = New SqlConnection(cs)
274 con.Open()
275 Dim cb1 As String = "insert into Cards_Staff(StaffID) VALUES (@d1)"
276 cmd = New SqlCommand(cb1)
277 cmd.Parameters.AddWithValue("@d1", txtID.Text)
278 cmd.Connection = con
279 cmd.ExecuteReader()
280 con.Close()
281 con = New SqlConnection(cs)
282 con.Open()
283 Dim cb2 As String = "insert into NoDues_Staff(StaffID) VALUES (@d1)"
284 cmd = New SqlCommand(cb2)
285 cmd.Parameters.AddWithValue("@d1", txtID.Text)
286 cmd.Connection = con
287 cmd.ExecuteReader()
288 con.Close()
289 con = New SqlConnection(cs)
290 con.Open()
291 Dim cb3 As String = "insert into Discount_Staff(StaffID,Discount) VALUES (@d1,0.00)"
292 cmd = New SqlCommand(cb3)
293 cmd.Parameters.AddWithValue("@d1", txtID.Text)
294 cmd.Connection = con
295 cmd.ExecuteReader()
296 con.Close()
297 LogFunc(lblUser.Text, "added new staff '" & txtStaffName.Text & "' has staff id '" & txtStaffID.Text & "'")
298 MessageBox.Show("Successfully saved", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
299 btnSave.Enabled = False
300 If con.State = ConnectionState.Open Then
301 con.Close()
302 End If
303 con.Close()
304
305 Catch ex As Exception
306 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
307 End Try
308 End Sub
309
310 Private Sub btnDelete_Click(sender As System.Object, e As System.EventArgs) Handles btnDelete.Click
311 Try
312 If MessageBox.Show("Do you really want to delete this record?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.Yes Then
313 DeleteRecord()
314 End If
315 Catch ex As Exception
316 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
317 End Try
318 End Sub
319 Public Sub DeleteRecord()
320 Try
321 Dim RowsAffected As Integer = 0
322 con = New SqlConnection(cs)
323 con.Open()
324 Dim cq As String = "delete from Staff where St_ID=@d1"
325 cmd = New SqlCommand(cq)
326 cmd.Parameters.AddWithValue("@d1", txtID.Text)
327 cmd.Connection = con
328 RowsAffected = cmd.ExecuteNonQuery()
329 If RowsAffected > 0 Then
330 LogFunc(lblUser.Text, "deleted the staff '" & txtStaffName.Text & "' has staff id '" & txtStaffID.Text & "'")
331 MessageBox.Show("Successfully deleted", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
332 Reset()
333 Else
334 MessageBox.Show("No record found", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Information)
335 Reset()
336 End If
337 con.Close()
338 Catch ex As Exception
339 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
340 End Try
341 End Sub
342
343 Private Sub btnUpdate_Click(sender As System.Object, e As System.EventArgs) Handles btnUpdate.Click
344 Try
345 If Len(Trim(txtStaffName.Text)) = 0 Then
346 MessageBox.Show("Please enter staff name", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
347 txtStaffName.Focus()
348 Exit Sub
349 End If
350 If rbMale.Checked = False And rbFemale.Checked = False Then
351 MessageBox.Show("Please select gender", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
352 Exit Sub
353 Exit Sub
354 End If
355 If Len(Trim(txtFatherName.Text)) = 0 Then
356 MessageBox.Show("Please enter father's name", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
357 txtFatherName.Focus()
358 Exit Sub
359 End If
360 If Len(Trim(cmbDesignation.Text)) = 0 Then
361 MessageBox.Show("Please select designation", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
362 cmbDesignation.Focus()
363 Exit Sub
364 End If
365 If Len(Trim(txtTempAddress.Text)) = 0 Then
366 MessageBox.Show("Please enter temporary address", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
367 txtTempAddress.Focus()
368 Exit Sub
369 End If
370 If Len(Trim(txtPermanentAddress.Text)) = 0 Then
371 MessageBox.Show("Please enter permanent address", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
372 txtPermanentAddress.Focus()
373 Exit Sub
374 End If
375 If Len(Trim(txtMobileNo.Text)) = 0 Then
376 MessageBox.Show("Please enter mobile no.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
377 txtMobileNo.Focus()
378 Exit Sub
379 End If
380 If Len(Trim(txtBasicSalary.Text)) = 0 Then
381 MessageBox.Show("Please enter basic salary", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
382 txtBasicSalary.Focus()
383 Exit Sub
384 End If
385 If ListView1.Items.Count = 0 Then
386 MessageBox.Show("Please add department to listview", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
387 cmbDepartment.Focus()
388 Exit Sub
389 End If
390 If Len(Trim(cmbSchoolName.Text)) = 0 Then
391 MessageBox.Show("Please select school name", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
392 cmbSchoolName.Focus()
393 Exit Sub
394 End If
395 If Len(Trim(cmbClassType.Text)) = 0 Then
396 MessageBox.Show("Please select class type", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
397 cmbClassType.Focus()
398 Exit Sub
399 End If
400 If Len(Trim(txtAccountName.Text)) = 0 Then
401 MessageBox.Show("Please enter account name", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
402 txtAccountName.Focus()
403 Exit Sub
404 End If
405 If Len(Trim(txtAccountNo.Text)) = 0 Then
406 MessageBox.Show("Please enter account no.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
407 txtAccountNo.Focus()
408 Exit Sub
409 End If
410 If Len(Trim(txtBank.Text)) = 0 Then
411 MessageBox.Show("Please enter bank", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
412 txtBank.Focus()
413 Exit Sub
414 End If
415 If Len(Trim(txtBranch.Text)) = 0 Then
416 MessageBox.Show("Please enter branch", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
417 txtBranch.Focus()
418 Exit Sub
419 End If
420 If Len(Trim(cmbStatus.Text)) = 0 Then
421 MessageBox.Show("Please select status", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
422 cmbStatus.Focus()
423 Exit Sub
424 End If
425 If rbMale.Checked = True Then
426 gender = rbMale.Text
427 End If
428 If rbFemale.Checked = True Then
429 gender = rbFemale.Text
430 End If
431 con = New SqlConnection(cs)
432 con.Open()
433 Dim cb As String = "Update Staff set StaffID=@d2, StaffName=@d3, DateOfJoining=@d4, Gender=@d5, FatherName=@d6, TemporaryAddress=@d7, PermanentAddress=@d8, Designation=@d9, Qualifications=@d10, DOB=@d11, PhoneNo=@d12, MobileNo=@d13, Email=@d14, Photo=@d15,Status='" & cmbStatus.Text & "',SchoolID=@d16,ClassType=@d17,Salary=@d18,AccountName=@d19,AccountNumber=@d20,Bank=@d21,Branch=@d22,IFSCcode=@d23 where St_ID=" & txtID.Text & ""
434 cmd = New SqlCommand(cb)
435 cmd.Connection = con
436 cmd.Parameters.AddWithValue("@d2", txtStaffID.Text)
437 cmd.Parameters.AddWithValue("@d3", txtStaffName.Text)
438 cmd.Parameters.AddWithValue("@d4", dtpDateOfJoining.Text)
439 cmd.Parameters.AddWithValue("@d5", gender)
440 cmd.Parameters.AddWithValue("@d6", txtFatherName.Text)
441 cmd.Parameters.AddWithValue("@d7", txtTempAddress.Text)
442 cmd.Parameters.AddWithValue("@d8", txtPermanentAddress.Text)
443 cmd.Parameters.AddWithValue("@d9", cmbDesignation.Text)
444 cmd.Parameters.AddWithValue("@d10", txtQualifications.Text)
445 cmd.Parameters.AddWithValue("@d11", dtpDOB.Text)
446 cmd.Parameters.AddWithValue("@d12", txtPhoneNo.Text)
447 cmd.Parameters.AddWithValue("@d13", txtMobileNo.Text)
448 cmd.Parameters.AddWithValue("@d14", txtEmail.Text)
449 cmd.Parameters.AddWithValue("@d16", txtSchoolID.Text)
450 cmd.Parameters.AddWithValue("@d17", cmbClassType.Text)
451 cmd.Parameters.AddWithValue("@d18", txtBasicSalary.Text)
452 cmd.Parameters.AddWithValue("@d19", txtAccountName.Text)
453 cmd.Parameters.AddWithValue("@d20", txtAccountNo.Text)
454 cmd.Parameters.AddWithValue("@d21", txtBank.Text)
455 cmd.Parameters.AddWithValue("@d22", txtBranch.Text)
456 cmd.Parameters.AddWithValue("@d23", txtIFSCcode.Text)
457 Dim ms As New MemoryStream()
458 Dim bmpImage As New Bitmap(Picture.Image)
459 bmpImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
460 Dim data As Byte() = ms.GetBuffer()
461 Dim p As New SqlParameter("@d15", SqlDbType.Image)
462 p.Value = data
463 cmd.Parameters.Add(p)
464 cmd.ExecuteNonQuery()
465 con = New SqlConnection(cs)
466 con.Open()
467 Dim cb1 As String = "delete from Staff_Department where StaffID=" & txtID.Text & ""
468 cmd = New SqlCommand(cb1)
469 cmd.Connection = con
470 cmd.ExecuteReader()
471 con.Close()
472 For i = 0 To ListView1.Items.Count - 1
473 con = New SqlConnection(cs)
474 Dim cd As String = "insert Into Staff_Department(StaffID,DepartmentID) VALUES (@d1,@d2)"
475 cmd = New SqlCommand(cd)
476 cmd.Connection = con
477 cmd.Parameters.AddWithValue("@d1", txtID.Text)
478 cmd.Parameters.AddWithValue("@d2", CInt(ListView1.Items(i).SubItems(1).Text))
479 con.Open()
480 cmd.ExecuteNonQuery()
481 con.Close()
482 Next
483 LogFunc(lblUser.Text, "updated the staff '" & txtStaffName.Text & "' has staff id '" & txtStaffID.Text & "'")
484 MessageBox.Show("Successfully updated", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
485 btnUpdate.Enabled = False
486 If con.State = ConnectionState.Open Then
487 con.Close()
488 End If
489 con.Close()
490
491 Catch ex As Exception
492 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
493 End Try
494 End Sub
495
496 Private Sub btnAdd_Click(sender As System.Object, e As System.EventArgs) Handles btnAdd.Click
497 Try
498 If Len(Trim(cmbDepartment.Text)) = 0 Then
499 MessageBox.Show("Please select department", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
500 cmbDepartment.Focus()
501 Exit Sub
502 End If
503 Dim temp As Integer
504 temp = ListView1.Items.Count()
505 If temp = 0 Then
506 Dim i As Integer
507 Dim lst As New ListViewItem(i)
508 lst.SubItems.Add(txtDepartmentID.Text)
509 lst.SubItems.Add(cmbDepartment.Text)
510 ListView1.Items.Add(lst)
511 i = i + 1
512 cmbDepartment.SelectedIndex = -1
513 Exit Sub
514 End If
515 For j = 0 To temp - 1
516 If (ListView1.Items(j).SubItems(2).Text = cmbDepartment.Text) Then
517 MessageBox.Show("Department already added", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
518 Exit Sub
519 End If
520 Next j
521 Dim k As Integer
522 Dim lst1 As New ListViewItem(k)
523 lst1.SubItems.Add(txtDepartmentID.Text)
524 lst1.SubItems.Add(cmbDepartment.Text)
525 ListView1.Items.Add(lst1)
526 k = k + 1
527 cmbDepartment.SelectedIndex = -1
528 Catch ex As Exception
529 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
530 End Try
531 End Sub
532
533 Private Sub btnRemove_Click(sender As System.Object, e As System.EventArgs) Handles btnRemove.Click
534 Try
535 If (ListView1.SelectedItems.Count > 0) Then
536 Dim itmCnt, i, t As Integer
537 ListView1.FocusedItem.Remove()
538 itmCnt = ListView1.Items.Count
539 t = 1
540 For i = 1 To itmCnt + 1
541
542 'Dim lst1 As New ListViewItem(i)
543 'ListView1.Items(i).SubItems(0).Text = t
544 t = t + 1
545 Next
546 btnRemove.Enabled = False
547 End If
548 Catch ex As Exception
549 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
550 End Try
551 End Sub
552
553 Private Sub ListView1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListView1.SelectedIndexChanged
554 btnRemove.Enabled = True
555 End Sub
556
557 Private Sub btnClose_Click(sender As System.Object, e As System.EventArgs) Handles btnClose.Click
558 Me.Close()
559 End Sub
560
561 Sub fillDesignation()
562 Try
563 con = New SqlConnection(cs)
564 con.Open()
565 adp = New SqlDataAdapter()
566 adp.SelectCommand = New SqlCommand("SELECT distinct (Designation) FROM Designation", con)
567 ds = New DataSet("ds")
568 adp.Fill(ds)
569 dtable = ds.Tables(0)
570 cmbDesignation.Items.Clear()
571 For Each drow As DataRow In dtable.Rows
572 cmbDesignation.Items.Add(drow(0).ToString())
573 Next
574 Catch ex As Exception
575 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
576 End Try
577 End Sub
578 Sub fillDepartment()
579 Try
580 con = New SqlConnection(cs)
581 con.Open()
582 adp = New SqlDataAdapter()
583 adp.SelectCommand = New SqlCommand("SELECT distinct (Departmentname) FROM Department", con)
584 ds = New DataSet("ds")
585 adp.Fill(ds)
586 dtable = ds.Tables(0)
587 cmbDepartment.Items.Clear()
588 For Each drow As DataRow In dtable.Rows
589 cmbDepartment.Items.Add(drow(0).ToString())
590 Next
591 Catch ex As Exception
592 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
593 End Try
594 End Sub
595 Private Sub frmStudent_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
596 fillDepartment()
597 fillDesignation()
598 fillClassType()
599 fillSchool()
600 End Sub
601
602 Private Sub btnGetData_Click(sender As System.Object, e As System.EventArgs) Handles btnGetData.Click
603 frmStaffRecord.Reset()
604 frmStaffRecord.lblSet.Text = "Staff Entry"
605 frmStaffRecord.ShowDialog()
606 End Sub
607
608 Private Sub cmbDepartment_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cmbDepartment.SelectedIndexChanged
609 Try
610 con = New SqlConnection(cs)
611 con.Open()
612 cmd = con.CreateCommand()
613 cmd.CommandText = "SELECT ID FROM Department where DepartmentName=@d1"
614 cmd.Parameters.AddWithValue("@d1", cmbDepartment.Text)
615 rdr = cmd.ExecuteReader()
616 If rdr.Read() Then
617 txtDepartmentID.Text = rdr.GetValue(0)
618 End If
619 If (rdr IsNot Nothing) Then
620 rdr.Close()
621 End If
622 If con.State = ConnectionState.Open Then
623 con.Close()
624 End If
625 Catch ex As Exception
626 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
627 End Try
628 End Sub
629
630 Private Sub cmbSchoolName_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cmbSchoolName.SelectedIndexChanged
631 Try
632 con = New SqlConnection(cs)
633 con.Open()
634 cmd = con.CreateCommand()
635 cmd.CommandText = "SELECT S_ID FROM SchoolInfo where SchoolName=@d1"
636 cmd.Parameters.AddWithValue("@d1", cmbSchoolName.Text)
637 rdr = cmd.ExecuteReader()
638 If rdr.Read() Then
639 txtSchoolID.Text = rdr.GetValue(0)
640 End If
641 If (rdr IsNot Nothing) Then
642 rdr.Close()
643 End If
644 If con.State = ConnectionState.Open Then
645 con.Close()
646 End If
647 Catch ex As Exception
648 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
649 End Try
650 End Sub
651
652 Private Sub txtBasicSalary_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtBasicSalary.KeyPress
653 Dim keyChar = e.KeyChar
654
655 If Char.IsControl(keyChar) Then
656 'Allow all control characters.
657 ElseIf Char.IsDigit(keyChar) OrElse keyChar = "."c Then
658 Dim text = Me.txtBasicSalary.Text
659 Dim selectionStart = Me.txtBasicSalary.SelectionStart
660 Dim selectionLength = Me.txtBasicSalary.SelectionLength
661
662 text = text.Substring(0, selectionStart) & keyChar & text.Substring(selectionStart + selectionLength)
663
664 If Integer.TryParse(text, New Integer) AndAlso text.Length > 16 Then
665 'Reject an integer that is longer than 16 digits.
666 e.Handled = True
667 ElseIf Double.TryParse(text, New Double) AndAlso text.IndexOf("."c) < text.Length - 3 Then
668 'Reject a real number with two many decimal places.
669 e.Handled = False
670 End If
671 Else
672 'Reject all other characters.
673 e.Handled = True
674 End If
675 End Sub
676 End Class